import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/util/image_utils.dart';

import '../../net/response/bed/bed_info_data.dart';

class CurrentBedInfoViewModel extends BaseListViewModel<String> {
  CurrentBedInfoViewModel(BuildContext context, this.bedId) : super(context);
  final String bedId;

  BedInfoData? bedInfo;

  @override
  Future<List<String>> requestListData() async {
    var data = await PostRequest.bedInfo(bedId);
    if ("0" == data['code'].toString()) {
      bedInfo = BedInfoData.fromJson(data['data']);
      return ["", ""];
    } else {
      throw data['msg'];
    }
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  Widget contentWidget() {
    return bedInfo == null
        ? Container()
        : ListView(
            padding: EdgeInsets.symmetric(vertical: 20, horizontal: 16),
            children: [
              CommonText(
                '床位信息',
                textSize: 20,
                fontWeight: FontWeight.bold,
              ),
              Container(
                height: 10,
              ),
              IconTitleTextWidget(
                '楼栋：',
                text: bedInfo?.buildingNo ?? "",
                showArrow: false,
                height: 30,
                padding: EdgeInsets.zero,
              ),
              IconTitleTextWidget(
                '楼层：',
                text: bedInfo?.floorNo??"",
                showArrow: false,
                height: 30,
                padding: EdgeInsets.zero,
              ),
              IconTitleTextWidget(
                '房间号：',
                text: bedInfo?.roomNo??"",
                showArrow: false,
                height: 30,
                padding: EdgeInsets.zero,
              ),
              IconTitleTextWidget(
                '床位号：',
                text: bedInfo?.bedNo??"",
                showArrow: false,
                height: 30,
                padding: EdgeInsets.zero,
              ),
              Container(
                height: 20,
              ),
              Gaps.line,
              bedInfo?.checkInElderInfoBean == null
                  ? Container(
                      child: Text(''),
                    )
                  : Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          height: 20,
                        ),

                        ///头像
                        Row(
                          children: [
                            bedInfo!.checkInElderInfoBean?.headimageId == null
                                ? ImageLoad(
                                    ImageUtils.getImgPath(bedInfo?.checkInElderInfoBean?.sexName=="男"?"nan":"nv"),
                                    width: 100,
                                    height: 100,
                                    fit: BoxFit.fill,
                                    isAsset: true,
                                  ).toCircle()
                                : ImageLoad(
                                    "${HttpApi.imageHead}${bedInfo?.checkInElderInfoBean?.headimageId}",
                                    width: 100,
                                    height: 100,
                                    fit: BoxFit.fill,
                                    isAsset: true,
                                  ).toCircle(),
                            Container(
                              width: 40,
                            ),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                CommonText(
                                  bedInfo?.checkInElderInfoBean?.customerName ??
                                      "",
                                  textSize: 22,
                                  fontWeight: FontWeight.bold,
                                ),
                                Container(
                                  height: 20,
                                ),
                                CommonText(
                                    '年龄：${bedInfo?.checkInElderInfoBean?.age}          性别：${bedInfo?.checkInElderInfoBean?.sexName}')
                              ],
                            )
                          ],
                        ),
                        Container(
                          height: 20,
                        ),
                        IconTitleTextWidget(
                          '入住日期：',
                          text: bedInfo?.checkInElderInfoBean?.intoDate??"",
                          showArrow: false,
                          height: 30,
                          padding: EdgeInsets.zero,
                        ),
                        IconTitleTextWidget(
                          '护理等级：',
                          text:
                              bedInfo?.checkInElderInfoBean?.branchNurseLevelName??"",
                          showArrow: false,
                          height: 30,
                          padding: EdgeInsets.zero,
                        ),
                        IconTitleTextWidget(
                          '身份证号：',
                          text: bedInfo?.checkInElderInfoBean?.cardNo??"",
                          showArrow: false,
                          height: 30,
                          padding: EdgeInsets.zero,
                        ),
                        IconTitleTextWidget(
                          '联系电话：',
                          text: bedInfo?.checkInElderInfoBean?.mobile??"",
                          showArrow: false,
                          height: 30,
                          padding: EdgeInsets.zero,
                        ),

                        IconTitleTextWidget(
                          '出生日期：',
                          text: bedInfo?.checkInElderInfoBean?.birthday??"",
                          showArrow: false,
                          height: 30,
                          padding: EdgeInsets.zero,
                        ),

                        Container(
                          height: 20,
                        ),

                        CommonText(
                          '家属信息',
                          textSize: 20,
                          fontWeight: FontWeight.bold,
                        ),
                        Container(
                          height: 10,
                        ),

                        ListView(
                          shrinkWrap: true,
                          physics: NeverScrollableScrollPhysics(),
                          children:
                              (bedInfo?.checkInElderInfoBean?.families ?? [])
                                  .map((e) {
                            return Column(
                              children: [
                                IconTitleTextWidget(
                                  '联系人：',
                                  text: e.name??"",
                                  showArrow: false,
                                  height: 30,
                                  padding: EdgeInsets.zero,
                                ),
                                IconTitleTextWidget(
                                  '关系：',
                                  text: e.relationshipName??"",
                                  showArrow: false,
                                  height: 30,
                                  padding: EdgeInsets.zero,
                                ),
                                IconTitleTextWidget(
                                  '联系电话：',
                                  text: e.mobile??"",
                                  showArrow: false,
                                  height: 30,
                                  padding: EdgeInsets.zero,
                                ),
                                Container(
                                  height: 10,
                                ),
                                Gaps.dividerLine
                              ],
                            );
                          }).toList(),
                        )
                      ],
                    )
            ],
          );
  }
}
